﻿/*
This file is part of Ingo Karstein's Web based PowerShell Console for SharePoint project

**Do not remove this comment**

Please see the project homepage at CodePlex:
  http://spwebpsconsole.codeplex.com/
  
The project is based upon my project "Web based PowerShell Console":
  http://webpsconsole.codeplex.com/

Please see my blog:
  http://ikarstein.wordpress.com

Licence: GPLv2
    Ingo Karstein's SharePoint 2010 Custom Ribbon Demo
    Copyright (C) 2011  Ingo Karstein, ikarstein@hotmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

namespace ik.SharePoint2010.SPWebPSConsole
{
    internal static class Extensions
    {
        internal static MyColor ToMyColor(this Color A)
        {
            return new MyColor
            {
                Color = A
            };
        }

        internal static string HtmlEncode(this char c)
        {
                int value = Convert.ToInt32(c);
                if( value > 127 )
                    return string.Format("&#{0};", value);
                else
                    return System.Convert.ToString(c);
        }

        internal static Color ToColor(this ConsoleColor cc)
        {
            Color c = Color.White;
            switch( cc )
            {
                case ConsoleColor.Black:
                    c = Color.Black;
                    break;
                case ConsoleColor.Blue:
                    c = Color.Blue;
                    break;
                case ConsoleColor.Cyan:
                    c = Color.Cyan;
                    break;
                case ConsoleColor.DarkBlue:
                    c = Color.DarkBlue;
                    break;
                case ConsoleColor.DarkCyan:
                    c = Color.DarkCyan;
                    break;
                case ConsoleColor.DarkGray:
                    c = Color.DarkGray;
                    break;
                case ConsoleColor.DarkGreen:
                    c = Color.DarkGreen;
                    break;
                case ConsoleColor.DarkMagenta:
                    c = Color.DarkMagenta;
                    break;
                case ConsoleColor.DarkRed:
                    c = Color.DarkRed;
                    break;
                case ConsoleColor.DarkYellow:
                    c = Color.Gold;
                    break;
                case ConsoleColor.Gray:
                    c = Color.Gray;
                    break;
                case ConsoleColor.Green:
                    c = Color.Green;
                    break;
                case ConsoleColor.Magenta:
                    c = Color.Magenta;
                    break;
                case ConsoleColor.Red:
                    c = Color.Red;
                    break;
                case ConsoleColor.White:
                    c = Color.White;
                    break;
                case ConsoleColor.Yellow:
                    c = Color.Yellow;
                    break;
            }
            return c;
        }
    }

    internal class MyColor : IComparable
    {
        public Color Color
        {
            get;
            set;
        }
        public int CompareTo(object obj)
        {
            int A = Color.ToArgb();
            int B = ( (MyColor)obj ).Color.ToArgb();
            if( A == B )
                return 0;
            if( A > B )
                return 1;
            return -1;
        }

        
    }
}